package fr.web325.servlet.api.cart;

import fr.web325.bean.Json;
import fr.web325.dao.ClientDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/api/pay")
public class Pay extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String order_id = req.getParameter("orderId");
        try {
            if(new ClientDao().editOrderSuccess(order_id)){
                // 支付成功 跳转我的订单界面
                resp.getWriter().print(new Json(201,null,"支付成功!").getRespJson());
            }else{
                resp.getWriter().print(new Json(202,null,"支付失败!").getRespJson());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
